﻿#define _CRT_SECURE_NO_WARNINGS
#define _WINSOCK_DEPRECATED_NO_WARNINGS
//#pragma comment(linker, "/STACK:1073741824") //谨防空间不够，事实上这会导致32bit系统报错
#include "login.h"
#include "hash.h"
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[])
{
    if (argv[1] != NULL)
    {
        string StartCmd = argv[1];//获取附加的第一个参数
        if (StartCmd == "UpdateFile")
        {
            system("powershell cp update.exe 主程序.exe");
            system("powershell start 主程序.exe RmOldFile");
            exit(0);
        }
        if (StartCmd == "RmOldFile")
        {
            system("powershell rm update.exe");
            cout << "程序升级成功！\n";
            PauseProcessCrossPlatform();
        }
    }
    string user_password;
    PrintWelcomeScreen();
    if (CheckFileExist())
        user_password = CreatNewUser();
    else
    {
        cout << "1.登录 2.创建用户\n";
        int user_choose; cin >> user_choose;
        if (user_choose == 2)
        {
            CreatNewUser();
            CleanConsole();
        }
        CleanConsole();
    }
    string username;
    {
        cout << "请输入用户名：";
        cin >> username;
        cout << "please input password: ";
        cin >> user_password;
        SetUsernameGolbal(username);//预推入用户名给salt
    }
    Login(username, user_password);
    {
    func:
        CleanConsole();
        int res = MainFunc(username);
        if (res == 1)
        {
            goto func;
        }
        else if (res == 0)
        {
            cout << "输入错误！请重新输入" << endl;
            PauseProcessCrossPlatform();
            CleanConsole();
            goto func;
        }
        else if (res == 3)
        {
            QuitProgram(user_password, username);
           // cout << "退出完毕.\n";
        }
    }
    return 0;
}